package com.test.ssm.article.service.impl;

import com.test.ssm.article.dao.SystemFunctionMapper;
import com.test.ssm.article.dao.SystemRoleMapper;
import com.test.ssm.article.entity.pojo.ArticleType;
import com.test.ssm.article.entity.pojo.SystemFunction;
import com.test.ssm.article.entity.pojo.SystemRole;
import com.test.ssm.article.entity.vo.SystemFunctionItem;
import com.test.ssm.article.service.SystemFunctionService;
import com.test.ssm.article.service.SystemRoleService;
import com.test.ssm.article.util.helper.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class SystemRoleServiceImpl implements SystemRoleService {
    @Autowired
    private SystemRoleMapper systemRoleMapper;

    @Override
    public List<SystemRole> getAll() {
        return systemRoleMapper.getAll();
    }

    @Override
    public MyPage<SystemRole> getAllByPage(Byte roleState, String roleName, Integer pageNum, Integer pageSize) {
        List<SystemRole> list =  systemRoleMapper.getAllByPage(roleState,roleName,pageNum,pageSize);
        Long count=  systemRoleMapper.countAllByLike(Integer.valueOf(roleState),roleName);
        MyPage<SystemRole> page = new MyPage<>(pageNum,pageSize,count,5,list);

        System.out.println("page = " + page);

        return page;
    }

    @Override
    public SystemRole checkIsExist(String roleName) {
        return systemRoleMapper.selectOneByName(roleName);
    }

    @Override
    public Boolean deleteOneById(String roleId) {
        return systemRoleMapper.deleteOneById(roleId);
    }

    @Override
    public long batchDelete(String roleIds) {
        return systemRoleMapper.batchDelete(roleIds);
    }

    @Override
    public Boolean add(SystemRole systemRole) {

        systemRole.setRoleId(UUID.randomUUID().toString());

        return systemRoleMapper.insertSelective(systemRole);
    }

    @Override
    public Boolean update(SystemRole systemRole) {

        Boolean flag = systemRoleMapper.updateByPrimaryKeySelective(systemRole);
        System.out.println("flag = " + flag);
        return flag;
    }
}
